package com.iotproject.blogservice.service.impl;

import com.alibaba.excel.EasyExcel;
import com.iotproject.blogservice.entity.BlogType;
import com.iotproject.blogservice.entity.excel.BlogTypeData;
import com.iotproject.blogservice.listener.BlogTypeExcelListener;
import com.iotproject.blogservice.mapper.BlogTypeMapper;
import com.iotproject.blogservice.service.BlogTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 * 博客类型 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-03-29
 */
@Service
public class BlogTypeServiceImpl extends ServiceImpl<BlogTypeMapper, BlogType> implements BlogTypeService {

    @Override
    public void importBlogTypeData(MultipartFile file, BlogTypeService blogTypeService) {
        try {
            //读取Excel 表数据
            InputStream fileStream = file.getInputStream();
            EasyExcel.read(fileStream, BlogTypeData.class, new BlogTypeExcelListener(blogTypeService)).sheet().doRead();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
